{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Configuration and deployment of multiple 5G UEs of Open Air Interface (OAI)\n",
    "## Objectives\n",
    "- Configure and deploy multiple UEs "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Multiple UE Configuration\n",
    "\n",
    "To connect multiple UEs, you'll need to set up a network namespace in Linux, as well as add route configurations, by following the commands below:\n",
    "\n",
    "**Step 1:** Creating a namespace:\n",
    "\n",
    "sudo ip netns add oai-ue2\n",
    "\n",
    "**Step 2:** Creating a pair of virtual interfaces (veth):\n",
    "\n",
    "sudo ip link add veth0 type veth peer name veth1\n",
    "\n",
    "**Step 3:** Moving one interface to the created namespace:\n",
    "\n",
    "sudo ip link set veth1 netns oai-ue2\n",
    "\n",
    "**Step 4:** Configuring an IP address for veth0 interface:\n",
    "\n",
    "sudo ip addr add 192.168.1.1/24 dev veth0\n",
    "\n",
    "**Step 5:** Configuring an IP address for veth1 interface within the namespace:\n",
    "\n",
    "sudo ip netns exec oai-ue2 ip addr add 192.168.1.2/24 dev veth1\n",
    "\n",
    "**Step 6:** Bringing up the veth0 interface:\n",
    "\n",
    "sudo ip link set veth0 up\n",
    "\n",
    "**Step 7:** Bringing up the veth1 interface within the namespace:\n",
    "\n",
    "sudo ip netns exec oai-ue2 ip link set veth1 up\n",
    "\n",
    "**Step 8:** Adding a route within the namespace:\n",
    "\n",
    "sudo ip netns exec oai-ue2 ip route add 192.168.70.128/26 via 192.168.1.1 dev veth1\n",
    "\n",
    "**Step 9:** Enabling packet forwarding on the system:\n",
    "\n",
    "sudo sysctl net.ipv4.conf.all.forwarding=1\n",
    "\n",
    "**Step 10:** Setting default policy for packet forwarding to ACCEPT:\n",
    "\n",
    "sudo iptables -P FORWARD ACCEPT\n",
    "\n",
    "**Step 11:** Enabling packet forwarding within the namespace:\n",
    "\n",
    "sudo ip netns exec oai-ue2 sysctl net.ipv4.conf.all.forwarding=1\n",
    "\n",
    "**Step 12:** Setting default policy for packet forwarding within the namespace to ACCEPT::\n",
    "\n",
    "sudo ip netns exec oai-ue2 iptables -P FORWARD ACCEPT\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Multiple UE Deployment\n",
    "\n",
    "**Step 1:** The deployment of multiple UEs is done in a similar way to a single UE, but it is necessary to enter the namespace before deploying. Run the following command:\n",
    "\n",
    "sudo ip netns exec oai-ue2 bash\n",
    "\n",
    "**Attention:** Remember to change the namespace according to the one you created earlier, in the example above \"oai-ue2\"\n",
    "\n",
    "**Step 2:** To deploy the UE, type in terminal:\n",
    "\n",
    "cd /home/dco1020/openairinterface5g/cmake_targets/ran_build/build/\n",
    "\n",
    "sudo RFSIMULATOR=192.168.70.129 ./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --rfsim --sa --nokrnmod -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf --uicc0.imsi 001010000000002\n",
    "\n",
    "**Attention:** Note that in the deployment command, the parameter \"--uicc0.imsi 001010000000002\" has been added, referring to the IMSI of the second UE, you MUST enter an IMSI that is present in the database (as shown in the \"UE Configuration\" section) and that IS NOT BEING USED BY ANOTHER UE."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
